const db = require('../db/index')

// 获取旅游轮播
exports.tourismImage = ((req,res)=>{
  const sql = 'select * from tourism_Carousel'
  db.query(sql,(err,result)=>{
    if(err)return res.cc(err.message)
    if(result.length===0) return res.cc("获取失败!")
    res.send({
        status:0,
        message:'获取旅游轮播成功!',
        data:result
    })
  })
})

// 获取跟团游的数据
exports.Follow = ((req,res)=>{
  const sql = 'select packageList_id,price2,title,image,TitleContent from tourism_packageList '
  db.query(sql,(err,result)=>{
    if(err)return res.cc(err.message)
    if(result.length===0) return res.cc("获取失败!")
    res.send({
        status:0,
        message:'跟团游数据获取成功!',
        data:result
    })
  })
})

// 获取跟团游详情数据
exports.FollowDetails = ((req,res)=>{
  const {packageList_id} = req.query
  // 跟团数据
  let packageList
  // 跟团标签
  let tabs
  // 跟团优惠
  let favorable
  // 跟团数据图片
  let swiper
  const sqlStr = 'select * from tourism_packageList where packageList_id = ?'
  db.query(sqlStr,packageList_id,(err,result)=>{
    if(err)return res.cc(err.message)
    if(result.length===0) return res.cc("获取失败!")
      packageList = result
    // 获取跟团标签
    const sql = 'select tabs_id,tabsName from tourism_tabs where packageList_id = ?'
    db.query(sql,packageList_id,(err,result)=>{
    if(err)return res.cc(err.message)
    if(result.length===0) return res.cc("获取失败!")
      tabs = result
      // 获取跟团优惠
      const sql2 = 'select favorable_id,favorableName from tourism_favorable where packageList_id = ?'
      db.query(sql2,packageList_id,(err,result)=>{
      if(err)return res.cc(err.message)
      if(result.length===0) return res.cc("获取失败!")
        favorable = result
          // 获取跟团优惠
          const sql3 = 'select swiper_id,image from tourism_swiper where packageList_id = ?'
          db.query(sql3,packageList_id,(err,result)=>{
          if(err)return res.cc(err.message)
          if(result.length===0) return res.cc("获取失败!")
            swiper = result
            res.send({
              status:0,
              message:'跟团游详情数据获取成功!',
              data:{
                packageList,
                tabs,
                favorable,
                swiper
              }
            })
          })
      })
    })
  })
  
})

// 获取精品推荐
exports.scenicSpot = ((req,res)=>{
  const sql = 'select beautiful_scenery_id,beautiful_scenery_name,star,beautiful_scenery_comment,image from beautiful_scenery'
  db.query(sql,(err,result)=>{
    if(err)return res.cc(err.message)
    if(result.length===0) return res.cc("获取失败!")
    res.send({
      status:0,
      message:'精品推荐数据获取成功!',
      data:result
  })
  })
})

// 精品推荐详情
exports.BoutiqueDetails = ((req,res)=>{
  const {id} = req.query
  const sqlStr = 'select * from beautiful_scenery where beautiful_scenery_id = ?'
  db.query(sqlStr,id,(err,result)=>{
    if(err)return res.cc(err.message)
    if(result.length===0) return res.cc("获取失败!")
    const beautiful = result
    const sql = 'select Meitu_id,Meitu_image from Meitu where beautiful_scenery_id = ?'
    db.query(sql,id,(err,result)=>{
      if(err)return res.cc(err.message)
      if(result.length===0) return res.cc("获取失败!")
      res.send({
          status:0,
          message:'精品推荐详情数据获取成功!',
          data:{
            beautiful,
            image: result
          }
      })
    })
  })
})


// 获取所有的精品景点数据
exports.BoutiqueAttractions = ((req,res)=>{
  const sql = 'select * from tourism_attractionsList'
  db.query(sql,(err,result)=>{
    if(err)return res.cc(err.message)
    if(result.length===0) return res.cc("获取失败!")
    res.send({
        status:0,
        message:'精品景点数据获取成功!',
        data:result
    })
  })
})

// 获取精品景点详情数据
exports.ScenicSpotDetails = ((req,res)=>{
  const {id} = req.query
  // 精品景点数据
  let packageList
  // 精品景点标签
  let tabs
  // 精品景点优惠
  let favorable
  // 精品景点数据图片
  let swiper
  const sqlStr = 'select * from tourism_attractionsList where attractionsList_id = ?'
  db.query(sqlStr,id,(err,result)=>{
    if(err)return res.cc(err.message)
    if(result.length===0) return res.cc("获取失败!")
      packageList = result
    // 获取精品景点标签
    const sql = 'select tabs_id,tabsName from attractionsList_tabs where attractionsList_id = ?'
    db.query(sql,id,(err,result)=>{
    if(err)return res.cc(err.message)
    if(result.length===0) return res.cc("获取失败!")
      tabs = result
      // 获取精品景点优惠
      const sql2 = 'select favorable_id,attractionsListName from attractionsList_favorable where attractionsList_id = ?'
      db.query(sql2,id,(err,result)=>{
      if(err)return res.cc(err.message)
      if(result.length===0) return res.cc("获取失败!")
        favorable = result
          const sql3 = 'select swiper_id,image from attractionsList_swiper where attractionsList_id =  ?'
          db.query(sql3,id,(err,result)=>{
          if(err)return res.cc(err.message)
          if(result.length===0) return res.cc("获取失败!")
            swiper = result
            res.send({
              status:0,
              message:'精品景点详情数据获取成功!',
              data:{
                packageList,
                tabs,
                favorable,
                swiper
              }
            })
          })
      })
    })
  })
})